﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Entities;
using Utility;
using BUS;

public partial class Administrator_Doanhnghiep_dangsanpham : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            load_dropdownlist();
        }
    }

    private void load_dropdownlist()
    {
        Tbl_loaisp_Collection loaispCollection = Tbl_loaisp_BUS.GetAll();
        ddl_loaisp.DataTextField = Tbl_loaisp_Columns.TenLoai.ToString();
        ddl_loaisp.DataValueField = Tbl_loaisp_Columns.STT.ToString();
        ddl_loaisp.DataSource = loaispCollection;
        ddl_loaisp.DataBind();
    }
    protected void bt_ok_Click(object sender, EventArgs e)
    {
        //try
        //{
            Tbl_sanpham_Entities sp = new Tbl_sanpham_Entities();
            sp.MaSP = txt_masp.Text;
            sp.TenSP = ftxt_tensp.Text;
            sp.GiaGoc = float.Parse(txt_giagoc.Text);
            sp.GiaBan = float.Parse(txt_giaban.Text);
            sp.TyLeGiamGia = float.Parse(txt_giaban.Text) / float.Parse(txt_giagoc.Text);
            sp.NgayDangSP = DateTime.Today.ToShortDateString();
            sp.ThoiGianSuDung = txt_thoigiansudung.Text;
            sp.ThongTinSanPham = ftxt_ttsp.Text;
            sp.DieuKienSuDung = ftxt_dksd.Text;
            sp.SoLuongBan = int.Parse(txt_sl.Text);
            sp.STT_doanhnghiep = 1;
            sp.TinhTrang = "Close";
            sp.LoaiSP = int.Parse(ddl_loaisp.SelectedValue);

            Tbl_sanpham_BUS.Insert(sp);
            Response.Redirect("~/Administrator/success.aspx?cmd=register");
        //}
        //catch 
        //    {
        //        Response.Redirect("~/Administrator/error.aspx");
        //    }
    }
}
